using System;
using Rubikev.Common.DependencyInjection;
using StructureMap.Configuration.DSL;

namespace Rubikev.StructureMap
{
   /// <summary>
   /// Scans the current directory's assemblies for any types that implement <see cref="IRegister"/> and adds them to the ObjectFactory
   /// </summary>
   public class ScanCurrentDirectoryRegister : Registry
   {
      public ScanCurrentDirectoryRegister()
      {
         string assemblyPath = AppDomain.CurrentDomain.BaseDirectory;
         Scan(assemblyScanner =>
                 {
                    assemblyScanner.AssembliesFromPath(assemblyPath);
                    assemblyScanner.AddAllTypesOf<IRegister>();
                 });
      }
   }
}